/*
	Copyright (C) 2011 Daniel C. Dennison (dandennison84@gmail.com).  All rights reserved.
	This file is licensed under the EPL 1.0 (Eclipse Public License 1.0)
	A copy of the license can be found at http://www.eclipse.org/legal/epl-v10.html
*/

package com.gmail.dandennison84.accounting

import org.junit.Before
import org.junit.Test
import groovy.text.SimpleTemplateEngine

class JournalEntryAmountTest {
	Account cashAccount

	@Before
	void before() {
		cashAccount = new Account(name:'Cash', accountType:AccountType.ASSETS, balanceType:BalanceType.DEBIT, closingType:ClosingType.PERMANENT,
			cashFlowStatementType:CashFlowStatementType.OPERATING_ACTIVITIES)
	}

	@Test
	void testAccountAmount() {
		JournalEntryAmount jea = new JournalEntryAmount(account:cashAccount, amount:1.0)
		assert cashAccount == jea.account
		assert 1.0 == jea.amount
	}

	@Test
	void testPrettyPrint() {
		JournalEntryAmount jea = new JournalEntryAmount(account:cashAccount, amount:1.0)

		String t = '$jea.account.name: $jea.amount'
		Map<String, String> binding = ['jea':jea]
		SimpleTemplateEngine ste = new SimpleTemplateEngine()
		String s = ste.createTemplate(t).make(binding).toString()
		assert 'Cash: 1.0' == s
	}
}
